package com.example.db;

import java.util.Map;

import com.example.ConditionHandlers.ActionHandler;
import com.example.messaging.MessageFactory;
import com.example.singletones.SQLHelper;

public class ActionsComplete extends AbstractDBAction {

	protected ActionsComplete(SQLHelper sqlHelper) {
		super(sqlHelper);
	}

	public void updateDB(Object sender, Map<String, Object> arg0) {
		sqlHelper.insertMainEventCat(arg0);
	}

	public boolean isApplicable(Object sender, Map<String, Object> args) {
		return sender instanceof ActionHandler && args.containsKey("status")
				&& args.containsKey("condition");
	}

	public String getName() {
		return ActionHandler.NAME;
	}

	public String updateParameter(String parameter, String str) {
		String parameterName = parameter.substring(parameter.indexOf('|') + 1,
				parameter.length() - 1);
		String sensorName = getName();
		int parameterLocation = MessageFactory.getInstance()
				.getParameterNumber(sensorName, parameterName);
		return str.replace(parameter, "value_" + Constants.SENSOR_NAME_POS
				+ "='" + sensorName + "' and key_" + parameterLocation + "='"
				+ parameterName + "' and value_" + parameterLocation);
	}

}
